#ifndef __UTIL_H
#define __UTIL_H
#include "common.h"

#define LL_ADD(item, list) do{                  \
    item->prev = NULL;                          \
    item->next = list;                          \
    if(list != NULL) list->prev = item;         \
    list = item;                                \
}while(0)


#define LL_REMOVE(item, list) do {		                        \
    if(item->prev != NULL) item->prev->next = item->next;       \
    if(item->next != NULL) item->next->prev = item->prev;       \
    if(list == item) list = item->next;                         \
    item->prev = item->next = NULL;                             \
} while(0)


void print_address(const char * name, uint32_t address);
void print_arp_table();
uint16_t icmp_checksum(uint16_t *addr, int count);
int get_fd_frombitmap(void);
int set_fd_frombitmap(int fd);
struct tcp_stream * get_accept_tcb(uint16_t d_port);
void print_eth_address(const char * name, const struct rte_ether_addr * eth_address);
void * get_host_info_from_fd(int fd);
struct local_host * get_host_info_from_ip_port(uint32_t d_ip, uint16_t d_port, uint8_t proto);
struct tcp_stream * get_tcp_stream_from_fd(int fd);
void error_print(const char * msg);
#endif